package com.slz3.business.module.orderManagement.ordPayDetail.service;

import com.slz3.business.frame.enums.ValidFlag;
import com.slz3.business.frame.module.Repositorys;
import com.slz3.business.frame.module.Services;
import com.slz3.business.frame.steward.PageableSteward;
import com.slz3.business.module.orderManagement.ordPayDetail.domain.OrdPayDetail;
import com.slz3.business.module.orderManagement.ordPayDetail.domain.OrdPayDetailFactory;
import com.slz3.business.module.orderManagement.ordPayDetail.steward.OrdPayDetailSpecification;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;

@Slf4j
@Service
public class OrdPayDetailServiceImpl implements OrdPayDetailService {
    @Override
    public OrdPayDetail save(OrdPayDetail ordPayDetail) {
        return Repositorys.ordPayDetail.save(OrdPayDetailFactory.initBaseFields(ordPayDetail));
    }
    @Override
    public Page<OrdPayDetail> page(MultiValueMap<String, String> params) {
        Page<OrdPayDetail> ordPayDetailPage = Repositorys.ordPayDetail.findAll(
                OrdPayDetailSpecification.findJoin(params), PageableSteward.extract(params)
        );
        return ordPayDetailPage;
    }


    @Override
    public OrdPayDetail modify(OrdPayDetail ordPayDetailNew) {
        return Repositorys.ordPayDetail.saveAndFlush(OrdPayDetailFactory.initBaseFields(ordPayDetailNew));
    }

    @Override
    public Optional<OrdPayDetail> single(UUID uuid) {
        return Repositorys.ordPayDetail.findById(uuid);
    }

    @Override
    public List<OrdPayDetail> findAllByUuids(Iterable<UUID> uuids) {
        return Repositorys.ordPayDetail.findAllById(uuids);
    }

    @Override
    public List<OrdPayDetail> delete(List<OrdPayDetail> ordPayDetailList) {
        ordPayDetailList.stream().forEach(item -> {
            item.setValidFlag(ValidFlag.DEL);
            OrdPayDetailFactory.initBaseFields(item);
        });
        return Services.ordPayDetailTransactional.batchModify(ordPayDetailList);
    }

}
